<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" session="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%--
- Author(s): Robert
- Date: 2018-03-29 16:55:01
- Description:
    --%>
<head>
<title>我创建的任务</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="<%=request.getContextPath()%>/common/nui/nui.js"
	type="text/javascript">
        </script>
</head>
<body style="width: 98%; height: 95%;">
<style>
	.mini-textbox{
		width: 100px;
	}
	.mini-buttonedit {
		width: 100px;
	}
</style>
	<div class="nui-panel" title="查询任务" iconCls="icon-add"
		style="width: 100%; height: 20%;" showToolbar="false"
		showFooter="true">
		<div id="form1" class="nui-form" align="left" style="height: 100%">
			<!-- 数据实体的名称 -->
			<input class="nui-hidden" name="criteria/_entity"
				value="com.zhmy.xmgl.zhmytask.ZhmyTask">
			<!-- 排序字段 -->
			<table id="table1" class="table" style="height: 100%">
				<tr>
					<td class="form_label">任务标题:</td>
					<td colspan="1"><input class="nui-textbox"
						name="criteria/_expr[1]/taskTitle" /> <input class="nui-hidden"
						name="criteria/_expr[1]/_op" value="like"> <input
						class="nui-hidden" name="criteria/_expr[1]/_likeRule" value="all">
					</td>
					<td class="form_label">任务状态:</td>
					<td colspan="1"><input class="nui-dictcombobox"
						dictTypeId="TASK_STATUS" name="criteria/_expr[2]/taskStatus" /> <input
						class="nui-hidden" name="criteria/_expr[2]/_op" value="=">
					</td>
					<td class="form_label">接收人:</td>
					<td colspan="1"><input id="lookup5"
						name="criteria/_expr[5]/taskSendee" class="nui-lookup"
						textField="name" valueField="name" popupWidth="auto"
						popup="#gridPanel5" grid="#datagrid5" multiSelect="false" /> <input
						class="nui-hidden" name="criteria/_expr[5]/_op" value="=">
					</td>
					<td class="form_label">所属项目:</td>
					<td colspan="1"><input id="lookup4" onvaluechanged="onDeptChanged"
						name="criteria/_expr[7]/zhmyProject.projectId" class="nui-lookup"
						textField="projectName" valueField="projectId" popupWidth="auto"
						popup="#gridPanel4" grid="#datagrid4" multiSelect="false" /> <input
						class="nui-hidden" name="criteria/_expr[7]/_op" value="=">
					</td>
					<td class="form_label">所属版本:</td>
					<td colspan="1"><input id="lookup7"
						name="criteria/_expr[8]/zhmyVersionChange.vcId" class="nui-lookup"
						textField="vcVersionNumber" valueField="vcId" popupWidth="auto"
						popup="#gridPanel7" grid="#datagrid7" multiSelect="false" /> <input
						class="nui-hidden" name="criteria/_expr[8]/_op" value="=">
					</td>
					<td rowspan="1">
						<a class="nui-button" onclick="search()">查询 </a>
						<a class="nui-button" onclick="reset()"> 重置 </a>
					</td>
				</tr>
			</table>
		</div>
	</div>
	<div class="nui-panel" title="我创建的任务列表" iconCls="icon-add"
		style="width: 100%; height: 85%;" showToolbar="false"
		showFooter="false">
		<div class="nui-toolbar" style="border-bottom: 0; padding: 0px;">
			<table style="width: 100%;">
				<tr>
					<td style="width: 100%;">
						 <a id="update" class="nui-button" iconCls="icon-edit" onclick="edit()">编辑 </a> 
						 <a class="nui-button" iconCls="icon-remove" onclick="remove()">删除 </a>
					</td>
				</tr>
			</table>
		</div>
		<div class="nui-fit">
			<div id="datagrid1" dataField="zhmytasks" class="nui-datagrid"
				style="width: 100%; height: 100%;"
				url="com.zhmy.xmgl.zhmytaskbiz.queryICreatedZhmyTasks.biz.ext"
				pageSize="10" showPageInfo="true" multiSelect="true"
				onselectionchanged="selectionChanged" allowSortColumn="false"
				ondrawcell="addLink">
				<div property="columns">
					<div type="indexcolumn"></div>
					<div type="checkcolumn"></div>
					<div field="taskId" headerAlign="center" allowSort="true"
						visible="false">任务id</div>
					<div field="taskTitle" headerAlign="center" allowSort="true">
						任务标题</div>
					<div field="taskStatus" headerAlign="center" allowSort="true"
						renderer="onTaskStatusRenderer">任务状态</div>
					<div field="taskType" headerAlign="center" allowSort="true"
						renderer="onTaskTypeRenderer">任务类型</div>
					<div field="taskFounder" headerAlign="center" allowSort="true">
						发布人</div>
					<div field="taskSendee" headerAlign="center" allowSort="true">
						接收人</div>
					<div field="zhmyVersionChange.vcVersionNumber" headerAlign="center" allowSort="true">
						版本</div>
					<div field="taskLevel" headerAlign="center" allowSort="true"
						renderer="onUrgentDegreeRenderer">紧急程度</div>
					<!--<div field="taskCtime" headerAlign="center" allowSort="true">
						创建时间</div>-->
					<div field="taskUtime" headerAlign="center" allowSort="true">
						更新时间</div>
					<div field="zhmyProject.projectName" headerAlign="center"
						allowSort="true">所属项目</div>
					<div name="oprate" headerAlign="center">操作</div>
				</div>
			</div>
		</div>
	</div>

	<!--  look up 1 -->
	<div id="gridPanel4" class="nui-panel" title="header"
		iconCls="icon-add" style="width: 450px; height: 250px;"
		showToolbar="true" showCloseButton="true" showHeader="false"
		bodyStyle="padding:0" borderStyle="border:0">
		<div property="toolbar"
			style="padding: 5px; padding-left: 8px; text-align: center;">
			<div style="float: left; padding-bottom: 2px;">
				<span>项目名称:</span> <input id="keyText4" class="nui-textbox"
					style="width: 160px;" onenter="onSearchClick4" /> <a
					class="nui-button" onclick="onSearchClick4">查询</a> <a
					class="nui-button" onclick="onClearClick4">清除</a>
			</div>
			<div style="float: right; padding-bottom: 2px;">
				<a class="nui-button" onclick="onCloseClick4">关闭</a>
			</div>
			<div style="clear: both;"></div>
		</div>
		<div id="datagrid4" class="nui-datagrid"
			style="width: 100%; height: 100%;" borderStyle="border:0"
			showPageSize="false" showPageIndex="false" dataField="orgs"
			url="com.zhmy.xmgl.zhmytaskbiz.queryProjectId.biz.ext">
			<div property="columns">
				<div type="checkcolumn"></div>
				<div field="projectFounder" width="120" headerAlign="center"
					allowSort="true">创建人</div>
				<div field="projectName" width="120" headerAlign="center"
					allowSort="true">项目名称</div>
			</div>
		</div>
	</div>

	<!--  look up 5 -->
	<div id="gridPanel5" class="nui-panel" title="header"
		iconCls="icon-add" style="width: 450px; height: 250px;"
		showToolbar="true" showCloseButton="true" showHeader="false"
		bodyStyle="padding:0" borderStyle="border:0">
		<div property="toolbar"
			style="padding: 5px; padding-left: 8px; text-align: center;">
			<div style="float: left; padding-bottom: 2px;">
				<span>接收人:</span> <input id="keyText5" class="nui-textbox"
					style="width: 160px;" onenter="onSearchClick5" /> <a
					class="nui-button" onclick="onSearchClick5">查询</a> <a
					class="nui-button" onclick="onClearClick5">清除</a>
			</div>
			<div style="float: right; padding-bottom: 2px;">
				<a class="nui-button" onclick="onCloseClick5">关闭</a>
			</div>
			<div style="clear: both;"></div>
		</div>
		<div id="datagrid5" class="nui-datagrid"
			style="width: 100%; height: 100%;" borderStyle="border:0"
			showPageSize="false" showPageIndex="false" dataField="people"
			url="com.zhmy.xmgl.zhmyprojectmanage.getPeopleListOfProject.biz.ext?projectid=1">
			<div property="columns">
				<div type="checkcolumn"></div>
				<div field="name" width="120" headerAlign="center"
					allowSort="true">姓名</div>
			</div>
		</div>
	</div>
	<!--  look up 7 -->
	<div id="gridPanel7" class="nui-panel" title="header"
		iconCls="icon-add" style="width: 450px; height: 250px;"
		showToolbar="true" showCloseButton="true" showHeader="false"
		bodyStyle="padding:0" borderStyle="border:0">
		<div property="toolbar"
			style="padding: 5px; padding-left: 8px; text-align: center;">
			<div style="float: left; padding-bottom: 2px;">
				<span>接收人:</span> <input id="keyText7" class="nui-textbox"
					style="width: 160px;" onenter="onSearchClick7" /> <a
					class="nui-button" onclick="onSearchClick7">查询</a> <a
					class="nui-button" onclick="onClearClick7">清除</a>
			</div>
			<div style="float: right; padding-bottom: 2px;">
				<a class="nui-button" onclick="onCloseClick7">关闭</a>
			</div>
			<div style="clear: both;"></div>
		</div>
		<div id="datagrid7" class="nui-datagrid"
			style="width: 100%; height: 100%;" borderStyle="border:0"
			showPageSize="false" showPageIndex="false" dataField="orgs"
			url="com.zhmy.xmgl.zhmyprojectmanage.getVersionListOfProject.biz.ext">
			<div property="columns">
				<div type="checkcolumn"></div>
				<div field="vcVersionNumber" width="120" headerAlign="center"
					allowSort="true">版本名称</div>
			</div>
		</div>
	</div>

	<script type="text/javascript">
/*	        var projectId = "<%=request.getParameter("projectId")%>";
	        if (projectId > 0 ) {
	        	$("[name$=projectId]").val(projectId);
	        }
        */
         var outProjectid = 1;
		
		//选择接收人关于项目联动的处理函数
		function onDeptChanged(e) {
			var projectid = nui.getbyName("criteria/_expr[7]/zhmyProject.projectId").getValue();
			outProjectid = projectid;
			//console.log("projectid="+outProjectid);
			
		    var url = "com.zhmy.xmgl.zhmyprojectmanage.getVersionListOfProject.biz.ext?projectid="+projectid;
		   nui.get("datagrid7").setUrl(url);
		   onSearchClick7();
		   
		      var url = "com.zhmy.xmgl.zhmyprojectmanage.getPeopleListOfProject.biz.ext?projectid="+projectid;
		   nui.get("datagrid5").setUrl(url);
		   onSearchClick5();
		}
            nui.parse();
            var grid = nui.get("datagrid1");

            var formData = new nui.Form("#form1").getData(false,false);
            grid.load(formData);
            
            //dict
            function onTaskTypeRenderer(e) {
            	return nui.getDictText('TASK_TYPE', e.value);
            }
           
            //dict
            function onTaskStatusRenderer(e) {
            	return nui.getDictText('TASK_STATUS', e.value);
            }
            
            //dict
            function onUrgentDegreeRenderer(e) {
            	return nui.getDictText('URGENT_DEGREE', e.value);
            }

            //编辑
            function edit() {
                var row = grid.getSelected();
                if (row) {
	                var task_status = row.taskStatus;
	                if (task_status > 2) {
	                	nui.alert("已接单任务不可修改","提示");
	                	return;
	                }
                
                    nui.open({
                        url: "<%=request.getContextPath()%>/xmgl/ZhmyNewTaskForm.jsp",
                        title: "编辑数据",
                        width: 900,
                        height: 650,
                        onload: function () {
                            var iframe = this.getIFrameEl();
                            var data = {pageType:"edit",record:{zhmytask:row}};
                            //直接从页面获取，不用去后台获取
                            iframe.contentWindow.setFormData(data);
                            },
                            ondestroy: function (action) {
                                grid.reload();
                            }
                            });
                        } else {
                            nui.alert("请选中一条记录","提示");
                        }
                    }

                    //删除
                    function remove(){
                        var rows = grid.getSelecteds();
                        if(rows.length > 0){
                            nui.confirm("确定删除选中记录？","系统提示",
                            function(action){
                                if(action=="ok"){
                                    var json = nui.encode({zhmytasks:rows});
                                    grid.loading("正在删除中,请稍等...");
                                    $.ajax({
                                        url:"com.zhmy.xmgl.zhmytaskbiz.deleteZhmyTasks.biz.ext",
                                        type:'POST',
                                        data:json,
                                        cache: false,
                                        contentType:'text/json',
                                        success:function(text){
                                            var returnJson = nui.decode(text);
                                            if(returnJson.exception == null){
                                                grid.reload();
                                                nui.alert("删除成功", "系统提示", function(action){
                                                    });
                                                }else{
                                                    grid.unmask();
                                                    nui.alert("删除失败", "系统提示");
                                                }
                                            }
                                            });
                                        }
                                        });
                                    }else{
                                        nui.alert("请选中一条记录！");
                                    }
                                }

                                //重新刷新页面
                                function refresh(){
                                    var form = new  nui.Form("#form1");
                                    var json = form.getData(false,false);
                                    grid.load(json);//grid查询
                                    nui.get("update").enable();
                                }

                                //查询
                                function search() {
                                    var form = new nui.Form("#form1");
                                    var json = form.getData(false,false);
                                    grid.load(json);//grid查询
                                }

                                //重置查询条件
                                function reset(){
                                    var form = new nui.Form("#form1");//将普通form转为nui的form
                                    form.reset();
                                }

                                //enter键触发查询
                                function onKeyEnter(e) {
                                    search();
                                }

                                //当选择列时
                                function selectionChanged(){
                                    var rows = grid.getSelecteds();
                                    if(rows.length>1){
                                        nui.get("update").disable();
                                    }else{
                                        nui.get("update").enable();
                                    }
                                }
                                
                                 //my4
			                    var grid4 = nui.get("datagrid4");
								var keyText4 = nui.get("keyText4");
								grid4.load();
							 	function onSearchClick4(e) { 
									grid4.load({
										key : keyText4.value 
									});
								}
								
								function onCloseClick4(e) {
									var lookup2 = nui.get("lookup4");
									lookup2.hidePopup(); 
								}
								
								function onClearClick4() {
									var lookup2 = nui.get("lookup4");
									lookup2.deselectAll();
								}
								
								//my5
			                    var grid5 = nui.get("datagrid5");
								var keyText5 = nui.get("keyText5");
								grid5.load();
							 	function onSearchClick5(e) { 
									grid5.load({
										key : keyText5.value 
									});
								}
								
								function onCloseClick5(e) {
									var lookup2 = nui.get("lookup5");
									lookup2.hidePopup(); 
								}
								
								function onClearClick5() {
									var lookup2 = nui.get("lookup5");
									lookup2.deselectAll();
								}
								
										//选择办班的操作代码
        var grid7 = nui.get("datagrid7");
		var keyText7 = nui.get("keyText7");
		//grid5.load();
		grid7.load({
				key : keyText7.value ,
				projectid: outProjectid
			});
	 	function onSearchClick7(e) { 
			grid7.load({
				key : keyText7.value ,
				projectid: outProjectid
			});
		}
			
		function onCloseClick7(e) {
			var lookup2 = nui.get("lookup7");
			lookup2.hidePopup(); 
		}
			
		function onClearClick7() {
			var lookup2 = nui.get("lookup7");
			lookup2.deselectAll();
		}
								
								//查看日志列表
                                function addLink(e){
									if(e.column.name == "oprate"){									
										var rowline = e.row.taskId;
										var task_status = e.row.taskStatus;
										
										var style1 = "style='margin: 2px; background:#555555; color:#fff; text-align: center; display: inline-block; border-radius:8px; padding:4px 10px; border:none;'";
										var style2 = "style='margin: 2px; background:#008cba; color:#fff; text-align: center; display: inline-block; border-radius:8px; padding:4px 10px; border:none;'";
										var style3 = "style='margin: 2px; background:#a7a7a7; color:#fff; text-align: center; display: inline-block; border-radius:8px; padding:4px 10px; border:none;'";
										
										var detailsButton = "<a><button "+style1+" onclick='openDetails("+rowline+")'>查看</button></a>";
										
										if (task_status == 4) {
											e.cellHtml = "<a><button "+style2+" onclick='copyText("+rowline+")'>完成</button></a>";
											e.cellHtml += detailsButton;
										} else {
											e.cellHtml = "<a><button "+style3+" disabled='disabled'>完成</button></a>";
											e.cellHtml += detailsButton;
										}
									}
								}
								//查看任务详情的按钮相应函数
								function openDetails(taskId) {
									nui.open({
									url: "<%=request.getContextPath()%>/xmgl/taskDetails.jsp?taskId="+ taskId,
									title : "任务详情",
									width : 600,
									height : 500,
								});
		}

		function copyText(rowline) {
			//alert('jaha'+rowline);

			var json = "{'rowLine':" + rowline + "}";
			//console.log("json"+json);

			$.ajax({
				url : "com.zhmy.xmgl.zhmytaskbiz.finishATask.biz.ext",
				type : 'POST',
				data : json,
				cache : false,
				contentType : 'text/json',
				success : function(text) {
					var returnJson = nui.decode(text);
					if (returnJson.exception == null) {
						grid.reload();
						nui.alert("完成任务成功", "系统提示", function(action) {
						});
					} else {
						grid.unmask();
						nui.alert("完成任务失败", "系统提示");
					}
				}
			});
		}
	</script>
</body>
</html>
